package com.lagou.edu;

import com.alibaba.druid.pool.DruidDataSource;
import com.lagou.edu.ioc.stereotype.Bean;
import com.lagou.edu.ioc.stereotype.ComponentScan;
import com.lagou.edu.ioc.stereotype.PropertySource;
import com.lagou.edu.ioc.stereotype.Value;

import javax.sql.DataSource;


@ComponentScan(basePackages = {"com.lagou.edu"})
@PropertySource({"jdbc.properties"})
public class SpringConfig {

    @Value("${jdbc.driver}")
    private String driverClassName;
    @Value("${jdbc.url}")
    private String url;
    @Value("${jdbc.username}")
    private String username;
    @Value("${jdbc.password}")
    private String password;


    @Bean("dataSource")
    public DataSource createDataSource(){
        DruidDataSource druidDataSource = new DruidDataSource();
        druidDataSource.setDriverClassName(driverClassName);
        druidDataSource.setUrl(url);
        druidDataSource.setUsername(username);
        druidDataSource.setPassword(password);
        return druidDataSource;
    }
}
